package com.ling.service;

import com.ling.bean.UserUpvoteBlog;
import com.ling.bean.UserUpvoteBlogExample;
import com.ling.dao.UserUpvoteBlogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserUpvoteBlogService {
    private final UserUpvoteBlogMapper userUpvoteBlogMapper;

    @Autowired
    public UserUpvoteBlogService(UserUpvoteBlogMapper userUpvoteBlogMapper) {
        this.userUpvoteBlogMapper = userUpvoteBlogMapper;
    }

    //判断是否存在指定记录
    public boolean hasUpvoted(UserUpvoteBlog userUpvoteBlog) {
        UserUpvoteBlogExample userUpvoteBlogExample = new UserUpvoteBlogExample();
        userUpvoteBlogExample.createCriteria().andUseridEqualTo(userUpvoteBlog.getUserid()).andUpvoteblogidEqualTo(userUpvoteBlog.getUpvoteblogid());
        List<UserUpvoteBlog> userUpvoteBlogs = userUpvoteBlogMapper.selectByExample(userUpvoteBlogExample);
        return !userUpvoteBlogs.isEmpty();
    }

    //写入记录
    public void saveUpvote(UserUpvoteBlog userUpvoteBlog) {
        userUpvoteBlogMapper.insertSelective(userUpvoteBlog);
    }

}
